﻿using DevExpress.XtraBars;
using DevExpress.XtraGrid.Views.Base;
using NAGFwk.BL;
using NAGFwk.UI;
using SilkeyERP.BL;

namespace SilkeyERP.UI.Entities.PaymentMethod
{
    public partial class ContentView : BaseContentDetail
    {
        private IBaseController<Model.PaymentMethod> _controller = new PaymentMethodController();
        public override string ModuleName { get { return "PaymentMethod"; } }

        public ContentView()
        {
            InitializeComponent();
        }

        public override void ShowModule(bool firstShow)
        {
            base.ShowModule(firstShow);
            MapItLoad(_controller);

            currencyBindingSource.DataSource = new CurrencyController().GetAll();
        }      

        private void bbiDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            MapItDelete(_controller);
        }

        private void gvBaseContentDetail_RowUpdated(object sender, RowObjectEventArgs e)
        {
            MapItUpdate(e, _controller);
        }

        private void bbiRefresh_ItemClick(object sender, ItemClickEventArgs e)
        {
            RefreshAll();
        }

        private void gvBaseContentDetail_ValidateRow(object sender, ValidateRowEventArgs e)
        {
            if (string.IsNullOrEmpty(((Model.PaymentMethod)e.Row).Description))
            {
                e.ErrorText = "Descripcion es Requerido.";
                e.Valid = false;
            }
        }

        private void RefreshAll()
        {
            _controller = MapItRefresh(new PaymentMethodController());
        }
    }
}
